package daily.oct;

import java.util.Arrays;

public class lc976 {
    public int largestPerimeter(int[] nums) {
        Arrays.sort(nums);
        for (int longest=nums.length-1;longest>=2;longest--){
            if (nums[longest-1]+nums[longest-2]>nums[longest]){
                return nums[longest]+nums[longest-1]+nums[longest-2];
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        int[] nums1={2,1,2};
        int[] nums2={1,2,1,10};
        lc976 lc=new lc976();
        System.out.println(lc.largestPerimeter(nums1));
        System.out.println(lc.largestPerimeter(nums2));
    }
}
